package com.greatwqs.wmall.common.module.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import static com.greatwqs.wmall.common.module.constants.HttpStatus.INTERNAL_SERVER_ERROR;
import static com.greatwqs.wmall.common.module.constants.HttpStatus.UNAUTHORIZED;

/**
 * HTTP 响应：错误 / 异常响应类
 *
 * @author wang-qingsong
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class HttpResponse {
    private String traceId;

    private Integer code;

    private String message;

    private Object data;

    public static HttpResponse of(String traceId, Integer code, String message) {
        return new HttpResponse(traceId, code, message, null);
    }

    public static HttpResponse of(String traceId, Integer code, String message, Object data) {
        return new HttpResponse(traceId, code, message, data);
    }

    public static HttpResponse internalServerError(String traceId) {
        return new HttpResponse(traceId, INTERNAL_SERVER_ERROR, "服务器忙，请稍后再试！", null);
    }

    public static HttpResponse loginTokenNotFoundOrExpired(String traceId) {
        return new HttpResponse(traceId, UNAUTHORIZED, "登录信息已过期，请重新登录！", null);
    }
}
